package com.guess.lolguessing.service.impl;

import com.guess.lolguessing.domain.po.Guessing;
import com.guess.lolguessing.domain.po.Matches;
import com.guess.lolguessing.mapper.GuessingMapper;
import com.guess.lolguessing.service.IGuessingService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-10-24
 */
@Service
public class GuessingServiceImpl extends ServiceImpl<GuessingMapper, Guessing> implements IGuessingService {

    @Override
    public Guessing getByMatchId(Integer matchId) {
        Guessing one = this.lambdaQuery().eq(Guessing::getMatchId, matchId).one();
        return one;
    }

    @Override
    public void updateA(Integer matchId, int amount) {
        Guessing one = this.lambdaQuery().eq(Guessing::getMatchId, matchId).one();
        one.setTeamAPoints(one.getTeamAPoints() + amount);
        this.updateById(one);
    }

    @Override
    public void updateB(Integer matchId, int amount) {
        Guessing one = this.lambdaQuery().eq(Guessing::getMatchId, matchId).one();
        one.setTeamBPoints(one.getTeamAPoints() + amount);
        this.updateById(one);
    }

    @Override
    public int getAmountTotalA(Long matchId, Integer teamId) {
        Guessing one = this.lambdaQuery().eq(Guessing::getMatchId, matchId)
                .eq(Guessing::getTeamAId, teamId).one();
        return one.getTeamAPoints();
    }

    @Override
    public int getAmountTotalB(Long matchId, Integer teamId) {
        System.out.println(matchId + " --- " + teamId);
        Guessing one = this.lambdaQuery().eq(Guessing::getMatchId, matchId)
                .eq(Guessing::getTeamBId, teamId).one();
        return one.getTeamBPoints();
    }
}
